<template>
<div class="icons">
<swiper :options="swiperOption" ref="mySwiper">
  <swiper-slide v-for="(page,index) of pages" :key="index">
    <div class="icon" v-for="item of page" :key="item.id">
      <div class="icon-imgbox">
        <img class="icon-imgbox-img" :src="item.imgUrl" alt="">
      </div>
      <div class="icon-title">{{item.desc}}</div>
    </div>
  </swiper-slide>
</swiper>
</div>
</template>

<script>
export default{
  name: 'HomeIcons',
	props: {
		iconList: Array
	},
  data () {
    return {
      swiperOption: {
        autoPlay: false
      }
    }
  },
  computed: {
		pages () {
			const pages = []
			this.iconList.forEach((item, index) => {
			let page = Math.floor(index / 8)
				if (!pages[page]) {
						pages[page] = []
					}
					pages[page].push(item)
			})
			return pages
		}
  }
}
</script>

<style lang="stylus" scoped>
@import '~styles/varibles.styl'
@import '~styles/mixins.styl'
.icons
  margin-top: .1rem
.icons >>> .swiper-container
  height: 0rem
  padding-bottom: 50%
  .icon
    position: relative
    width: 25%
    padding-bottom: 25%
    float: left
    .icon-imgbox
      position: absolute
      top: 0rem
      left: 0rem
      right: 0rem
      bottom: .44rem
      padding: .1rem
      box-sizing: border-box
      .icon-imgbox-img
        height: 100%
        margin: 0 auto
        display: block
    .icon-title
      position: absolute
      left: 0
      right: 0
      bottom: 0
      height: .44rem
      line-height: .44rem
      text-align: center
      color: #333
      ellipsis()
</style>
